/**
 *
 */
package com.dhcc.frame.collection;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @author 谢进军
 *
 */
public class TimerTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TimerTask timerTask = new MyTimerTask();
		TimerTask timerTask2 = new MyTimerTask2();
        //running timer task as daemon thread
        Timer timer = new Timer(true);
        timer.scheduleAtFixedRate(timerTask, 0, 3*1000);
        timer.scheduleAtFixedRate(timerTask2, 0, 3*1000);
//        System.out.println("TimerTask started");
        //cancel after sometime
        try {
            Thread.sleep(120000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        timer.cancel();
        System.out.println("TimerTask cancelled");
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
	}

}
